package cn.itsource.domain.user;

import cn.hutool.core.lang.RegexPool;
import cn.itsource.basic.domain.BaseDomain;
import cn.itsource.basic.domain.CreatePassword;
import cn.itsource.domain.login.LoginInfo;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import lombok.AllArgsConstructor;
import lombok.Data;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * @author: hong
 * @Description:
 * @Date: Created in 12:34 2022/2/25
 * @Modified: By:
 */
@Data
@AllArgsConstructor
@TableName( "t_user")
public class User extends LoginInfo implements BaseDomain, CreatePassword {
    public User() {
    }

    public User(String s) {
        this.username = s;
    }

    public interface PhoneRegister{}
    public interface EmailRegister{}
    public interface UserInfo{}
    @TableId(type = IdType.INPUT)
    private Long id;
    @NotNull(message = "用户名不能为空",groups = {UserInfo.class})
    @Size(min =1,message = "用户名最小长度不能小于三位",groups = {UserInfo.class})
    private String username;
    @Email(message = "员工的邮箱不正确",groups = {EmailRegister.class})
    private String email;
    @Pattern(regexp= RegexPool.MOBILE,message = "手机号格式不正确",groups = {PhoneRegister.class})
    private String phone;

    private String salt;
    @NotNull(message = "用户密码不能为空",groups = {PhoneRegister.class,EmailRegister.class})
    @Size(min =6,message = "用户密码最小长度不能小于六位",groups = {PhoneRegister.class})
    private String password;

    @TableField(exist = false)
    private String configPassword;

    private Integer state;

    private Integer age;

    private Date createTime;

    private String headImg;

    private Boolean del;
    @TableField(exist = false)
    private String code;
    @TableField(exist = false)
    private Long shopId;
    @TableField(exist = false)
    private Integer type;
    /**
     * 做一些初始化参数的动作,比如初始化密码,盐,时间等
     * @return
     */
    public User init(){
        //设置雪花id
        this.setSnowflakeId();
        //给创建时间赋值
        this.createTime = new Date ();
        //初始化盐值
        this.createSalt();
        //将密码进行md5加密
        this.passwordMD5();
        return this;
    }




}
